<?php
/**
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     pmvc_formTextArea
 * Purpose:  renders a text area
 * -------------------------------------------------------------
 */

use pmvc\template\smarty\SmartyUtil;

function smarty_function_pmvc_formTextArea(array $params, &$smarty) {

    $request = SmartyUtil::getRegisteredObject($smarty, "Request", true);

    // id=
    if (!isset($params["id"])
    	&& isset($params["name"])) {
    	$params["id"] = $params["name"];
    }

    // value
    $value = "";
    if (isset($params["value"])) {
    	$value = $params["value"];
    	unset($params["value"]);
    }
	if (isset($params["name"])
    	&& $request->hasParameter($params["name"])) {
    	$value = $request->getParameter($params["name"]);
    }

    // render it
    $ret = '<textarea '.SmartyUtil::renderParamsAsAttributes($params, $smarty).'>'.htmlspecialchars($value).'</textarea>';
    return SmartyUtil::returnOrAssign($smarty, $params, $ret);
}

?>